package javase;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;

/**
 * @author hck soccerlover9527@gmail.com
 */
public class Test {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Interesting interesting = new Interesting();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 2, 0L, TimeUnit.SECONDS, new SynchronousQueue<>());
        Future<?> submit = threadPoolExecutor.submit(interesting::add);
        Future<?> submit1 = threadPoolExecutor.submit(interesting::add);
        Object o = submit.get();
        o = submit1.get();
        System.out.println(interesting.a == interesting.b);
    }
}


class Interesting {
    volatile int a = 1;
    volatile int b = 1;

    public void add() {
        System.out.println("add start");
        for (int i = 0; i < 10000; i++) {
            a++;
            b++;
        }
        System.out.println("add done");
    }

    public void compare() {
        System.out.println("compare start");
        for (int i = 0; i < 10000; i++) {
            //a始终等于b吗？
            if (a < b) {
                System.out.printf("a:%d,b:%d,%b%n", a, b, a > b);
                //最后的a>b应该始终是false吗？
            }
        }
        System.out.println("compare end");
    }
}